﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityModel;
using FluentNHibernate.Mapping;
using Iesi.Collections.Generic;

namespace MyFluentNHibernate.Mappings
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Id(u => u.UserID).GeneratedBy.Identity() ;
            Map(u => u.UserName);
            Map(u => u.Password);
            Map(u => u.CreateTime);
            HasOne<UserDetail>(u => u.Detail).Cascade.All().Fetch.Select();
            HasMany<Order>(u => u.Orders).AsSet().KeyColumn("UserID").Cascade.All();
        }
    }



    public class UserDetailMap : ClassMap<UserDetail>
    {
        public UserDetailMap()
        {
            Id(u => u.UserID).Column("UserID").GeneratedBy.Foreign("User");
            HasOne<User>(d => d.User).Cascade.All().Constrained();
            Map(u => u.LastUpdated).Nullable();
            Component<PersonName>(u => u.Name, p =>
            {
                p.Map(o => o.FirstName).Column("[First Name]");
                p.Map(o => o.LastName).Column("[Last Name]");
            });
        }
    }
}
